/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.catalog;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.catalog.CatalogService;
import shop.services.front.catalog.bean.Catalog;

import javax.annotation.Resource;
import java.util.List;

/**
 * @类名称：CatalogController
 * @创建人：Wzl
 * @创建时间：2017-09-20 下午15:34:37
 * @版本号：1.0
 * @描述：商品类别
 */
@Controller
@RequestMapping("/front/catalog/")
public class CatalogController extends FrontBaseController<Catalog> {
    @Resource
    private CatalogService catalogService;
    @Override
    public Services<Catalog> getService() {
        return catalogService;
    }

    /**
     * 跳转到分类页面（列表）
     *
     * @return
     */
    @RequestMapping("toCatalogList")
    public String toCatalogList() {
        return "/front/catalog/catalogSingleList";
    }
    /**
     * 跳转到分类页面（二级）
     *
     * @return
     */
    @RequestMapping("toCatalogDetail")
    public String toCatalogDetail() {
        return "/front/catalog/catalogDetail";
    }


    /**
     * 查询商品目录列表（首页）
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectCatalogList")
    @ResponseBody
    public JSONResult selectCatalogList(Catalog catalog) throws Exception {
        List<Catalog> rsList = catalogService.selectParentList(catalog);//一级目录
        for(Catalog catalogInfo : rsList){
            catalog.setPid(catalogInfo.getId());
            List<Catalog> rsList2 = catalogService.selectChildrenList(catalog);//二级目录
            catalogInfo.setChildren(rsList2);
        }
        jsonResult = new JSONResult();
        jsonResult.setData(rsList);
        return jsonResult;
    }
}
